package com.xinchuang.service.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xinchuang.comment.R;
import com.xinchuang.service.TryOutModService;
import com.xinchuang.utils.CheckUtil;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.text.SimpleDateFormat;

import com.xinchuang.utils.DateUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;

@Service
public class TryOutModServiceImpl implements TryOutModService {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public String getTryOutReport(JSONObject jsonObject) {
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        if (jsonObject == null || jsonObject.size() < 1
        ) {
            return "{\"data\":{\"screwTemperature\":[{\"stageName\":\"T0\",\"temperatureValue\":\"34\"}],\"tryOutDate\":\"2022-06-07\",\"dwellPressure\":\"xxx\",\"packingbagReturnCount\":\"xxx\",\"packingbagSpec\":\"xxx\",\"packingbagReceiveCount\":\"xxx\",\"hotRunnerTemperature\":\"56\",\"packingbagExceptionCount\":\"44\",\"moldId\":\"1\",\"storageEndPoint\":\"a\",\"breakdownDetialContent\":\"故障内容\",\"moldTemperature\":\"34\",\"serialNumber\":\"QR/HT-JK-4\",\"totalTime\":\"7\",\"moldWeight\":\"11\",\"fixTime\":\"5\",\"materialReceiveCount\":\"xxx\",\"noteId\":\"1\",\"exceptionHour\":\"3\",\"materialName\":\"xxx\",\"versionId\":\"1\",\"productionTakt\":\"周\",\"perCount\":\"2\",\"projectName\":\"xxx\",\"dwellSpeed\":\"167\",\"dwellTime\":\"xxx\",\"projectManager\":\"xxx\",\"exceptionRemark\":\"异常时间记录备注\",\"dryingTemperature\":\"35\",\"reportName\":\"试模报告1\",\"materialConsumeCount\":\"xxx\",\"costTimeRemark\":\"2\",\"produceMoldCount\":\"100\",\"dryingTime\":\"5\",\"debugMoldCount\":\"3\",\"cartonConsumeCount\":\"xxx\",\"loadTime\":\"2\",\"tryOutTimes\":\"xxx\",\"cartonReturnCount\":\"xxx\",\"cartonSpec\":\"xxx\",\"fixDetialContent\":\"xxx\",\"tryOutCompanyId\":1,\"demoProduceTime\":\"2022-06-08\",\"ejectionEjectionParams\":[{\"ejectionposition\":\"xxx\",\"ejectionStageName\":\"T0\",\"ejectionTempresure\":\"xxx\",\"ejectionSpeed\":\"xxx\"}],\"waitDetailContent\":\"xxx\",\"unloaTime\":\"6\",\"concessionalReceivingCount\":\"7\",\"materialSpec\":\"xxx\",\"cartonReceiveCount\":\"xxx\",\"qualifiedMoldCount\":\"3\",\"debugTime\":\"6\",\"tryOutEngineer\":\"xxx\",\"breakdownTime\":\"4\",\"tryOutTypeId\":1,\"exceptionPeriod\":\"5\",\"cartonExceptionCount\":\"xxx\",\"materialReturnCount\":\"xxx\",\"packingbagConsumeCount\":\"34\",\"waitTime\":\"3\",\"tryOutDevice\":\"xxx\",\"collingTime\":\"4\",\"sequentialValveFeedingMode\":[\"1\"],\"materialExceptionCount\":\"xxx\"}}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String getTryOutRecord(JSONObject jsonObject) {
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        if (jsonObject == null || jsonObject.size() < 1
        ) {
            return "{\"data\":{\"unloadEndtime\":\"2022-06-11 18:40:01\",\"reachedTime\":\"2022-06-11 09:00:00\",\"debugStarttime\":\"2022-06-11 13:30:00\",\"fixStarttime\":\"2022-06-11 11:30:00\",\"waitEndtime\":\"2022-06-11 10:30:00\",\"breakdownStarttime\":\"2022-06-11 10:30:01\",\"fixTime\":\"3\",\"noteId\":\"1\",\"loadEndttime\":\"2022-06-11 09:01:00\",\"breakdownEndtime\":\"2022-06-11 10:30:08\",\"debugTime\":\"2\",\"fixEndtime\":\"2022-06-11 12:30:00\",\"loadStarttime\":\"2022-06-11 09:00:01\",\"loadTime\":\"5\",\"unloadTime\":\"1\",\"demoProduceEndtime\":\"2022-06-11 18:30:00\",\"demoProduceStarttime\":\"2022-06-11 16:30:00\",\"waitStarttime\":\"2022-06-11 10:00:00\",\"breakDownTime\":\"6\",\"debugEndTime\":\"2022-06-11 14:00:00\",\"waitTime\":\"4\",\"demoProduceTime\":\"7\",\"unloadStarttime\":\"2022-06-11 18:30:01\"}}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String getTryOutRecordList(JSONObject jsonObject) {
        //jsonobject解析获取项目负责人
        String username = jsonObject.getString("username");
        //jsonobject解析获取模具名称
        String moldName = jsonObject.getString("moldName");
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        //jsonobject解析获取页码
        String pageNum = jsonObject.getString("pageNum");
        //jsonobject解析获取每页数量
        String pageSize = jsonObject.getString("pageSize");
        //jsonobject解析获取模具编号
        String moldId = jsonObject.getString("moldId");
        if (
                "1".equals(noteId)
                        &&
                        "1".equals(pageNum)
        ) {
            return "{\"msg\":\"获取成功\",\"code\":200,\"data\":{\"noteName\":\"xxx通知单\",\"recordCount\":\"T0\",\"moldId\":\"模具xxx\",\"noteId\":\"1\",\"tongName\":\"shixx\"},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String addTryOutRecord(JSONObject jsonObject) {
        //jsonobject解析获取模具到达时间
        String reachedTime = jsonObject.getString("reachedTime");
        //jsonobject解析获取上模开始时间
        String loadStarttime = jsonObject.getString("loadStarttime");
        //jsonobject解析获取等待开始时间
        String waitStarttime = jsonObject.getString("waitStarttime");
        //jsonobject解析获取上模结束时间
        String loadEndttime = jsonObject.getString("loadEndttime");
        //jsonobject解析获取等待结束时间
        String waitEndtime = jsonObject.getString("waitEndtime");
        //jsonobject解析获取设备故障开始时间
        String breakdownStarttime = jsonObject.getString("breakdownStarttime");
        //jsonobject解析获取设备故障结束时间
        String breakdownEndtime = jsonObject.getString("breakdownEndtime");
        //jsonobject解析获取修模开始时间
        String fixStarttime = jsonObject.getString("fixStarttime");
        //jsonobject解析获取修模结束时间
        String fixEndtime = jsonObject.getString("fixEndtime");
        //jsonobject解析获取调试开始时间
        String debugStarttime = jsonObject.getString("debugStarttime");
        //jsonobject解析获取调试结束时间
        String debugEndTime = jsonObject.getString("debugEndTime");
        //jsonobject解析获取样件生产开始时间
        String demoProduceStarttime = jsonObject.getString("demoProduceStarttime");
        //jsonobject解析获取样件生产结束时间
        String demoProduceEndtime = jsonObject.getString("demoProduceEndtime");
        //jsonobject解析获取下模开始时间
        String unloadStarttime = jsonObject.getString("unloadStarttime");
        //jsonobject解析获取下模结束时间
        String unloadEndtime = jsonObject.getString("unloadEndtime");
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        if (
                "2022-06-11 09:00:00".equals(reachedTime)
                        &&
                        "2022-06-11 09:00:01".equals(loadStarttime)
                        &&
                        "2022-06-11 09:01:00".equals(loadEndttime)
                        &&
                        "2022-06-11 10:00:00".equals(waitStarttime)
                        &&
                        "2022-06-11 10:30:00".equals(waitEndtime)
                        &&
                        "2022-06-11 10:30:01".equals(breakdownStarttime)
                        &&
                        "2022-06-11 10:30:08".equals(breakdownEndtime)
                        &&
                        "2022-06-11 11:30:00".equals(fixStarttime)
                        &&
                        "2022-06-11 12:30:00".equals(fixEndtime)
                        &&
                        "2022-06-11 13:30:00".equals(debugStarttime)
                        &&
                        "2022-06-11 14:00:00".equals(debugEndTime)
                        &&
                        "2022-06-11 16:30:00".equals(demoProduceStarttime)
                        &&
                        "2022-06-11 18:30:00".equals(demoProduceEndtime)
                        &&
                        "2022-06-11 18:30:01".equals(unloadStarttime)
                        &&
                        "2022-06-11 18:40:01".equals(unloadEndtime)
                        &&
                        "1".equals(noteId)
        ) {
            return "{\"msg\":\"保存成功\",\"code\":200,\"data\":{},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String addTryOutReport(JSONObject jsonObject) {
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        //jsonobject解析获取名称
        String reportName = jsonObject.getString("reportName");
        //jsonobject解析获取编号
        String serialNumber = jsonObject.getString("serialNumber");
        //jsonobject解析获取版本Id
        String versionId = jsonObject.getString("versionId");
        //jsonobject解析获取试模日期
        String tryOutDate = jsonObject.getString("tryOutDate");
        //jsonobject解析获取项目名称
        String projectName = jsonObject.getString("projectName");
        //jsonobject解析获取模具编号
        String moldId = jsonObject.getString("moldId");
        //jsonobject解析获取试模设备
        String tryOutDevice = jsonObject.getString("tryOutDevice");
        //jsonobject解析获取试模次数
        String tryOutTimes = jsonObject.getString("tryOutTimes");
        //jsonobject解析获取试模类型Id
        String tryOutTypeId = jsonObject.getString("tryOutTypeId");
        //jsonobject解析获取试模单位Id
        String tryOutCompanyId = jsonObject.getString("tryOutCompanyId");
        //jsonobject解析获取试模调试工程师
        String tryOutEngineer = jsonObject.getString("tryOutEngineer");
        //jsonobject解析获取项目工程师
        String projectManager = jsonObject.getString("projectManager");
        //jsonobject解析获取上模等待用时（H）
        String loadTime = jsonObject.getString("loadTime");
        //jsonobject解析获取等待总时数（H）
        String waitTime = jsonObject.getString("waitTime");
        //jsonobject解析获取设备故障用时（H）
        String breakdownTime = jsonObject.getString("breakdownTime");
        //jsonobject解析获取修模用时（H）
        String fixTime = jsonObject.getString("fixTime");
        //jsonobject解析获取调试用时（H）
        String debugTime = jsonObject.getString("debugTime");
        //jsonobject解析获取样件生产时间（H）
        String demoProduceTime = jsonObject.getString("demoProduceTime");
        //jsonobject解析获取下模时间（H)
        String unloaTime = jsonObject.getString("unloaTime");
        //jsonobject解析获取当天合计用时总数(H)
        String totalTime = jsonObject.getString("totalTime");
        //jsonobject解析获取用时记录备注
        String costTimeRemark = jsonObject.getString("costTimeRemark");
        //jsonobject解析获取开始结束时间段（H）
        String exceptionPeriod = jsonObject.getString("exceptionPeriod");
        //jsonobject解析获取时间（H）
        String exceptionHour = jsonObject.getString("exceptionHour");
        //jsonobject解析获取等待详细内容
        String waitDetailContent = jsonObject.getString("waitDetailContent");
        //jsonobject解析获取修模详细内容
        String fixDetialContent = jsonObject.getString("fixDetialContent");
        //jsonobject解析获取设备故障内容
        String breakdownDetialContent = jsonObject.getString("breakdownDetialContent");
        //jsonobject解析获取异常时间记录备注
        String exceptionRemark = jsonObject.getString("exceptionRemark");
        //jsonobject解析获取调试模数
        String debugMoldCount = jsonObject.getString("debugMoldCount");
        //jsonobject解析获取生产模数
        String produceMoldCount = jsonObject.getString("produceMoldCount");
        //jsonobject解析获取合格品数
        String qualifiedMoldCount = jsonObject.getString("qualifiedMoldCount");
        //jsonobject解析获取让步接收数
        String concessionalReceivingCount = jsonObject.getString("concessionalReceivingCount");
        //jsonobject解析获取每模件数
        String perCount = jsonObject.getString("perCount");
        //jsonobject解析获取单模重量（KG)
        String moldWeight = jsonObject.getString("moldWeight");
        //jsonobject解析获取生产节拍（S)
        String productionTakt = jsonObject.getString("productionTakt");
        //jsonobject解析获取材料规格
        String materialSpec = jsonObject.getString("materialSpec");
        //jsonobject解析获取材料领用数
        String materialReceiveCount = jsonObject.getString("materialReceiveCount");
        //jsonobject解析获取材料退库数
        String materialReturnCount = jsonObject.getString("materialReturnCount");
        //jsonobject解析获取材料消耗数
        String materialConsumeCount = jsonObject.getString("materialConsumeCount");
        //jsonobject解析获取材料异常说明
        String materialExceptionCount = jsonObject.getString("materialExceptionCount");
        //jsonobject解析获取纸箱规格
        String cartonSpec = jsonObject.getString("cartonSpec");
        //jsonobject解析获取纸箱领用数
        String cartonReceiveCount = jsonObject.getString("cartonReceiveCount");
        //jsonobject解析获取纸箱退库数
        String cartonReturnCount = jsonObject.getString("cartonReturnCount");
        //jsonobject解析获取纸箱消耗数
        String cartonConsumeCount = jsonObject.getString("cartonConsumeCount");
        //jsonobject解析获取纸箱异常说明
        String cartonExceptionCount = jsonObject.getString("cartonExceptionCount");
        //jsonobject解析获取包装袋规格
        String packingbagSpec = jsonObject.getString("packingbagSpec");
        //jsonobject解析获取包装袋领用数
        String packingbagReceiveCount = jsonObject.getString("packingbagReceiveCount");
        //jsonobject解析获取包装袋退库数
        String packingbagReturnCount = jsonObject.getString("packingbagReturnCount");
        //jsonobject解析获取包装袋消耗数
        String packingbagConsumeCount = jsonObject.getString("packingbagConsumeCount");
        //jsonobject解析获取包装袋异常说明
        String packingbagExceptionCount = jsonObject.getString("packingbagExceptionCount");
        //jsonobject解析获取材料名称/牌号
        String materialName = jsonObject.getString("materialName");
        //jsonobject解析获取烘料温度
        String dryingTemperature = jsonObject.getString("dryingTemperature");
        //jsonobject解析获取烘料时间
        String dryingTime = jsonObject.getString("dryingTime");
        //jsonobject解析获取储料终点位置
        String storageEndPoint = jsonObject.getString("storageEndPoint");
        //jsonobject解析获取保压时间
        String dwellTime = jsonObject.getString("dwellTime");
        //jsonobject解析获取保压压力
        String dwellPressure = jsonObject.getString("dwellPressure");
        //jsonobject解析获取保压速度
        String dwellSpeed = jsonObject.getString("dwellSpeed");
        //jsonobject解析获取冷却时间
        String collingTime = jsonObject.getString("collingTime");
        //jsonobject解析获取模温
        String moldTemperature = jsonObject.getString("moldTemperature");
        //jsonobject解析获取热流道温度
        String hotRunnerTemperature = jsonObject.getString("hotRunnerTemperature");
        //jsonobject解析获取射胶参数对象数组) Ejectio
        JSONArray ejectionEjectionParams = jsonObject.getJSONArray("ejectionEjectionParams");
        //jsonobject解析获取螺杆温度
        JSONArray screwTemperature = jsonObject.getJSONArray("screwTemperature");
        //jsonobject解析获取顺序阀进胶方式
        JSONArray sequentialValveFeedingMode = jsonObject.getJSONArray("sequentialValveFeedingMode");
        if (
                "1".equals(noteId)
                        &&
                        "试模报告1".equals(reportName)
                        &&
                        "QR/HT-JK-4".equals(serialNumber)
                        &&
                        "1".equals(versionId)
                        &&
                        "2022-06-07".equals(tryOutDate)
                        &&
                        "xxx".equals(projectName)
                        &&
                        "1".equals(moldId)
                        &&
                        "xxx".equals(tryOutDevice)
                        &&
                        "xxx".equals(tryOutTimes)
                        &&
                        "1".equals(tryOutTypeId)
                        &&
                        "1".equals(tryOutCompanyId)
                        &&
                        "xxx".equals(tryOutEngineer)
                        &&
                        "xxx".equals(projectManager)
                        &&
                        "2".equals(loadTime)
                        &&
                        "3".equals(waitTime)
                        &&
                        "4".equals(breakdownTime)
                        &&
                        "5".equals(fixTime)
                        &&
                        "6".equals(debugTime)
                        &&
                        "2022-06-08".equals(demoProduceTime)
                        &&
                        "6".equals(unloaTime)
                        &&
                        "7".equals(totalTime)
                        &&
                        "2".equals(costTimeRemark)
                        &&
                        "5".equals(exceptionPeriod)
                        &&
                        "3".equals(exceptionHour)
                        &&
                        "xxx".equals(waitDetailContent)
                        &&
                        "xxx".equals(fixDetialContent)
                        &&
                        "故障内容".equals(breakdownDetialContent)
                        &&
                        "异常时间记录备注".equals(exceptionRemark)
                        &&
                        "3".equals(debugMoldCount)
                        &&
                        "100".equals(produceMoldCount)
                        &&
                        "3".equals(qualifiedMoldCount)
                        &&
                        "7".equals(concessionalReceivingCount)
                        &&
                        "2".equals(perCount)
                        &&
                        "11".equals(moldWeight)
                        &&
                        "周".equals(productionTakt)
                        &&
                        "xxx".equals(materialSpec)
                        &&
                        "xxx".equals(materialReceiveCount)
                        &&
                        "xxx".equals(materialReturnCount)
                        &&
                        "xxx".equals(materialConsumeCount)
                        &&
                        "xxx".equals(materialExceptionCount)
                        &&
                        "xxx".equals(cartonSpec)
                        &&
                        "xxx".equals(cartonReceiveCount)
                        &&
                        "xxx".equals(cartonReturnCount)
                        &&
                        "xxx".equals(cartonConsumeCount)
                        &&
                        "xxx".equals(cartonExceptionCount)
                        &&
                        "xxx".equals(packingbagSpec)
                        &&
                        "xxx".equals(packingbagReceiveCount)
                        &&
                        "xxx".equals(packingbagReturnCount)
                        &&
                        "34".equals(packingbagConsumeCount)
                        &&
                        "44".equals(packingbagExceptionCount)
                        &&
                        "xxx".equals(materialName)
                        &&
                        "35".equals(dryingTemperature)
                        &&
                        "5".equals(dryingTime)
                        &&
                        "a".equals(storageEndPoint)
                        &&
                        "xxx".equals(dwellTime)
                        &&
                        "xxx".equals(dwellPressure)
                        &&
                        "167".equals(dwellSpeed)
                        &&
                        "4".equals(collingTime)
                        &&
                        "34".equals(moldTemperature)
                        &&
                        "56".equals(hotRunnerTemperature)
                        &&
                        "[{\"ejectionposition\":\"xxx\",\"ejectionStageName\":\"T0\",\"ejectionTempresure\":\"xxx\",\"ejectionSpeed\":\"xxx\"}]".equals(JSON.toJSONString(ejectionEjectionParams))
                        &&
                        "[{\"stageName\":\"T0\",\"temperatureValue\":\"34\"}]".equals(JSON.toJSONString(screwTemperature))
                        &&
                        "[\"1\"]".equals(JSON.toJSONString(sequentialValveFeedingMode))
        ) {
            return "{\"msg\":\"保存成功\",\"code\":200,\"data\":{},\"success\":true}";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

    @Override
    public String postTryOutReport(JSONObject jsonObject) {
        //jsonobject解析获取通知单Id
        String noteId = jsonObject.getString("noteId");
        if (jsonObject == null || jsonObject.size() < 1
        ) {
            return "";
        }
        return JSON.toJSONString(R.success("无数据"));
    }

}
